<template>
    <div>
     <CategoryHeadVue them="修改地址"></CategoryHeadVue>
     <van-address-edit
     :area-list="areaList"
     show-delete
     show-set-default
     show-search-result
     :search-result="searchResult"
     :area-columns-placeholder="['请选择', '请选择', '请选择']"
     @save="onSave"
     @delete="onDelete"
     @change-detail="onChangeDetail"
     />
    </div>
 </template>
 
 <script>
 import { areaList } from '@vant/area-data';
 import { Toast} from 'vant';
 import CategoryHeadVue from '@/components/Category-head.vue';
 import axios from '@/Utils/server';
 let userid = localStorage.getItem("userid")
 export default {
  name:"useraddaderss-vue",
  components:{
     CategoryHeadVue
  },
  data() {
     return {
       areaList,
       searchResult: [],
     };
   },
   methods: {
    onSave(info) {
      axios({
      method:"post",
      url:"/api/address/update",
      data:{
        addressid:this.$route.query.addressid,
          userid:userid,
          name:info.name,
          tel:info.tel,
          province:info.province,
          city:info.city,
          county:info.county,
          addressDetail:info.addressDetail,
          isDefault:info.isDefault
      }
      })
      .then(res=>{
      console.log(res.data);
        this.$router.back()
      // }
    })
  },
     onDelete() {
       axios.post("/api/address/delete",`addressid=${this.$route.query.addressid}`)
       .then(res=>{
        if(res.data.code==200){
            Toast('删除成功');
            this.$router.push("/useraderss")
        }
       })
     },
     onChangeDetail(val) {
       if (val) {
         this.searchResult = [
           {
             name: '黄龙万科中心',
             address: '杭州市西湖区',
           },
         ];
       } else {
         this.searchResult = [];
       }
     },
 }
 
 }
 </script>
 
 <style>
 
 </style>